<?php
global $_GPC, $_W;
$uniacid = $_W['uniacid'];
$id = $_GPC['id'];
$cate_id = $_GPC['cate_id'];
$res = $this->res;
$plus = $this->plus;
load()->func('tpl');
$keywords = $_GPC['keywords'];
$condition = "";
if (!empty($keywords)) {
	if (strrpos($keywords, " ")) {
		$keywords = explode(" ", $keywords);
		$result_num = count($keywords);
		if ($result_num == 1) {
			$condition .= " AND CONCAT(`title`) LIKE '%{$keywords[0]}%'";
		}
		if ($result_num == 2) {
			$condition .= " AND CONCAT(`title`) LIKE '%{$keywords[0]}%' AND CONCAT(`title`) LIKE '%{$keywords[1]}%'";
		}
		if ($result_num == 3) {
			$condition .= " AND CONCAT(`title`) LIKE '%{$keywords[0]}%' AND CONCAT(`title`) LIKE '%{$keywords[1]}%' AND CONCAT(`title`) LIKE '%{$keywords[2]}%'";
		}
		if ($result_num == 4) {
			$condition .= " AND CONCAT(`title`) LIKE '%{$keywords[0]}%' AND CONCAT(`title`) LIKE '%{$keywords[1]}%' AND CONCAT(`title`) LIKE '%{$keywords[2]}%' AND CONCAT(`title`) LIKE '%{$keywords[3]}%'";
		}
		if ($result_num == 5) {
			$condition .= " AND CONCAT(`title`) LIKE '%{$keywords[0]}%' AND CONCAT(`title`) LIKE '%{$keywords[1]}%' AND CONCAT(`title`) LIKE '%{$keywords[2]}%' AND CONCAT(`title`) LIKE '%{$keywords[3]}%' AND CONCAT(`title`) LIKE '%{$keywords[4]}%'";
		}
		if ($result_num == 6) {
			$condition .= " AND CONCAT(`title`) LIKE '%{$keywords[0]}%' AND CONCAT(`title`) LIKE '%{$keywords[1]}%' AND CONCAT(`title`) LIKE '%{$keywords[2]}%' AND CONCAT(`title`) LIKE '%{$keywords[3]}%' AND CONCAT(`title`) LIKE '%{$keywords[4]}%' AND CONCAT(`title`) LIKE '%{$keywords[5]}%'";
		}
		if ($result_num == 7) {
			$condition .= " AND CONCAT(`title`) LIKE '%{$keywords[0]}%' AND CONCAT(`title`) LIKE '%{$keywords[1]}%' AND CONCAT(`title`) LIKE '%{$keywords[2]}%' AND CONCAT(`title`) LIKE '%{$keywords[3]}%' AND CONCAT(`title`) LIKE '%{$keywords[4]}%' AND CONCAT(`title`) LIKE '%{$keywords[5]}%' AND CONCAT(`title`) LIKE '%{$keywords[6]}%'";
		}
	} else {
		$condition .= " AND CONCAT(`title`) LIKE '%{$keywords}%'";
	}
}
$list = pdo_fetchall("SELECT * FROM " . tablename($this->tableitemall) . " WHERE uniacid = :uniacid AND status=1" . $condition . "ORDER BY `displayorder` DESC,`id` DESC LIMIT 5", array(':uniacid' => $uniacid));
if ($list) {
	foreach ($list as $key => $value) {
		$list[$key]['itempic'] = tomedia($list[$key]['itempic'] . "_200x200.jpg");
	}
}
$pagename = '商品搜索';
include $this->template('search_wx');